<?php

namespace App\Exports;

use Encore\Admin\Grid\Exporters\ExcelExporter;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithMapping;
use App\Models\User;
use App\Models\CrmConfig;

class DialExport extends ExcelExporter implements WithMapping, WithHeadings, ShouldAutoSize
{

    //这里是导出来的文件的名字和格式
    protected $fileName = '呼叫记录.xlsx';
    //这里是excel的标题
    public function headings(): array
    {
        return [
            '编号',
            '呼叫类型',
            '客户姓名',
            '主叫号码',
            '被叫号码',
            '通话坐席',
            '呼叫时间',
            '通话市场',
            '通话状态',
        ];
    }

    public function map($callRecords): array
    {
        $call_type = [0=>'',1=>'普通来电',2=>'外呼去电'];
        return [
            $callRecords->id,
            $call_type[$callRecords->call_type],
            $callRecords->client_name,
            $callRecords->call_from,
            $callRecords->call_to,
            $callRecords->employee_id,
            $callRecords->call_at,
            $callRecords->call_duration,
            CrmConfig::getKeyValue('call_status')[$callRecords->call_status],
            $callRecords->client_name,
        ];
    }



}
